package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RecordArchiveset;
import com.ruoyi.system.service.IRecordArchivesetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 案卷目录配置Controller
 *
 * @author admin
 * @date 2022-02-23
 */
@RestController
@RequestMapping("/system/archiveset")
public class RecordArchivesetController extends BaseController {
    @Autowired
    private IRecordArchivesetService recordArchivesetService;

    /**
     * 查询案卷目录配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordArchiveset recordArchiveset) {
        startPage();
        List<RecordArchiveset> list = recordArchivesetService.selectRecordArchivesetList(recordArchiveset);
        return getDataTable(list);
    }

    /**
     * 导出案卷目录配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:export')")
    @Log(title = "案卷目录配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordArchiveset recordArchiveset) {
        List<RecordArchiveset> list = recordArchivesetService.selectRecordArchivesetList(recordArchiveset);
        ExcelUtil<RecordArchiveset> util = new ExcelUtil<RecordArchiveset>(RecordArchiveset.class);
        util.exportExcel(response, list, "案卷目录配置数据");
    }

    /**
     * 获取案卷目录配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:query')")
    @GetMapping(value = "/{archivesetId}")
    public AjaxResult getInfo(@PathVariable("archivesetId") Long archivesetId) {
        return AjaxResult.success(recordArchivesetService.selectRecordArchivesetByArchivesetId(archivesetId));
    }

    /**
     * 新增案卷目录配置
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:add')")
    @Log(title = "案卷目录配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordArchiveset recordArchiveset) {
        return toAjax(recordArchivesetService.insertRecordArchiveset(recordArchiveset));
    }

    /**
     * 修改案卷目录配置
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:edit')")
    @Log(title = "案卷目录配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordArchiveset recordArchiveset) {
        return toAjax(recordArchivesetService.updateRecordArchiveset(recordArchiveset));
    }

    /**
     * 删除案卷目录配置
     */
    @PreAuthorize("@ss.hasPermi('system:archiveset:remove')")
    @Log(title = "案卷目录配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{archivesetIds}")
    public AjaxResult remove(@PathVariable Long[] archivesetIds) {
        return toAjax(recordArchivesetService.deleteRecordArchivesetByArchivesetIds(archivesetIds));
    }
}
